/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.threads;

/**
 *
 * @author andersonribeiro
 */
public class RunPingPong implements Runnable {

    private String palavra;
    private int delay;

    public RunPingPong(String palavra, int delay) {
        this.palavra = palavra;
        this.delay = delay;
    }

    public void run() {

        try {
            for (;;) {
                System.out.print(palavra + "\n");
                Thread.sleep(delay);
            }
        } catch (Exception e) {
            System.err.println("Erro");
            return;
        }

    }

    public static void main(String[] args) {

        Runnable ping = new RunPingPong("ping", 500);
        Runnable pong = new RunPingPong("PONG", 1000);
        new Thread(ping).start();
        new Thread(pong).start();
        
    }
}
